package com.yunhe.test;

import java.util.ArrayList;
import java.util.List;
import org.apache.ibatis.session.SqlSession;
import com.yunhe.bean.CommodityClassify;
import com.yunhe.bean.CommodityInfo;
import com.yunhe.bean.LeavingReply;
import com.yunhe.bean.page;
import com.yunhe.inter.CommodityInfoInter;
import com.yunhe.inter.LeavingMessageInter;
import com.yunhe.inter.CommodityClassifyInter;
import com.yunhe.util.SqlSessionFactoryUtil;

public class test {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
     test te =new test();
     int a=te.countc();
    System.out.println(a);
   
	}
	   //展示商品方法
		public List<CommodityInfo> showc(page pg){
			SqlSession sqlSession;
		    sqlSession = SqlSessionFactoryUtil.openSqlSession();
		    CommodityInfoInter commMapper =  sqlSession.getMapper(CommodityInfoInter.class);
		    List<CommodityInfo> list=new ArrayList<CommodityInfo>();
		    list=commMapper.ShowCommodity(pg);
		    sqlSession.close();
			return list;
		}
		//获得总商品数方法
		public int countc(){
			SqlSession sqlSession;
		    sqlSession = SqlSessionFactoryUtil.openSqlSession();
		    CommodityInfoInter commMapper =  sqlSession.getMapper(CommodityInfoInter.class);
		    int num=commMapper.CountCommodity();
		    sqlSession.close();
			return num;
		}
		//删除商品方法
		public void deletec(int id){
			SqlSession sqlSession;
		    sqlSession = SqlSessionFactoryUtil.openSqlSession();
		    CommodityInfoInter commMapper =  sqlSession.getMapper(CommodityInfoInter.class);
		    commMapper.DeleteCommodity(id);
		    sqlSession.commit();
		    sqlSession.close();		    
		}
		//增加商品方法
		public void addc(CommodityInfo commodityinfo){
			SqlSession sqlSession;
		    sqlSession = SqlSessionFactoryUtil.openSqlSession();
		    CommodityInfoInter commMapper =  sqlSession.getMapper(CommodityInfoInter.class);
			commMapper.AddCommodity(commodityinfo);
			sqlSession.commit();
		    sqlSession.close();	
		}
	    //修改商品方法
		public void changec(CommodityInfo commodityinfo){
			SqlSession sqlSession;
		    sqlSession = SqlSessionFactoryUtil.openSqlSession();
		    CommodityInfoInter commMapper =  sqlSession.getMapper(CommodityInfoInter.class);
		    commMapper.ChangeCommodity(commodityinfo);
		    sqlSession.commit();
		    sqlSession.close();		    
		}
		//展示评论留言
		public List showm(page pg){
			SqlSession sqlSession;
		    sqlSession = SqlSessionFactoryUtil.openSqlSession();
		    LeavingMessageInter commMapper =  sqlSession.getMapper(LeavingMessageInter.class);
		    List list=commMapper.ShowMeassage(pg);
		    sqlSession.close();	
		    return list;
		}
		//留言数
		public int countm(){
			SqlSession sqlSession;
		    sqlSession = SqlSessionFactoryUtil.openSqlSession();
		    LeavingMessageInter commMapper =  sqlSession.getMapper(LeavingMessageInter.class);
		    int count=commMapper.CountMessage();
		    sqlSession.close();
		    return count;
		}
		//删除留言
		public void deletem(int id){
			SqlSession sqlSession;
		    sqlSession = SqlSessionFactoryUtil.openSqlSession();
		    LeavingMessageInter commMapper =  sqlSession.getMapper(LeavingMessageInter.class);
		    commMapper.DeleteMessage(id);
		    commMapper.DeleteMessageReply(id);
		    sqlSession.commit();
		    sqlSession.close();	
		}
		//回复留言并更新留言状态
		public void replym(LeavingReply lr){
			SqlSession sqlSession;
		    sqlSession = SqlSessionFactoryUtil.openSqlSession();
		    LeavingMessageInter commMapper =  sqlSession.getMapper(LeavingMessageInter.class); 
		    commMapper.InsertReply(lr);
		    commMapper.RefreshReply(lr);
		    sqlSession.commit();
		    sqlSession.close();	
		}
		//修改留言
		public void modifym(LeavingReply lr){
			SqlSession sqlSession;
		    sqlSession = SqlSessionFactoryUtil.openSqlSession();
		    LeavingMessageInter commMapper =  sqlSession.getMapper(LeavingMessageInter.class); 
		    commMapper.ModifyReply(lr);
		    sqlSession.commit();
		    sqlSession.close();	
		}
		//分类商品
		public  List<CommodityClassify> classifyc(page pg){
			SqlSession sqlSession;
		    sqlSession = SqlSessionFactoryUtil.openSqlSession();
		    CommodityClassifyInter commMapper =  sqlSession.getMapper(CommodityClassifyInter.class); 
		     List<CommodityClassify> list=commMapper.CommodityClassify(pg);
		      for (int i = 0; i < list.size(); i++) {
				  if(i==0){
					  CommodityClassify cc=new CommodityClassify();
					  cc.setBig_id(list.get(i).getBig_id());
					  cc.setBig_name(list.get(i).getBig_name());
			          list.add(0,cc);
				  }
				  if(i>0&&list.get(i).getBig_id()>list.get(i-1).getBig_id()){
					  CommodityClassify cc=new CommodityClassify();
					  cc.setBig_id(list.get(i).getBig_id());
					  cc.setBig_name(list.get(i).getBig_name());
					  list.add(i,cc);
				  }
				  }
		     sqlSession.close();
		     return list;
		}
		//分类数
		public int classifyCount(){
			SqlSession sqlSession;
		    sqlSession = SqlSessionFactoryUtil.openSqlSession();
		    CommodityClassifyInter commMapper =  sqlSession.getMapper(CommodityClassifyInter.class); 
			 int count=commMapper.ClassifyCount();
			 return count;
		}
		//小分类删除
		public void deletecl(int id){
			SqlSession sqlSession;
		    sqlSession = SqlSessionFactoryUtil.openSqlSession();
		    CommodityClassifyInter commMapper =  sqlSession.getMapper(CommodityClassifyInter.class); 
		    commMapper.DeleteSmallClassify(id);
		    sqlSession.commit();
		    sqlSession.close();
		}
		//大分类删除
		public void deletecla(int id){
			SqlSession sqlSession;
		    sqlSession = SqlSessionFactoryUtil.openSqlSession();
		    CommodityClassifyInter commMapper =  sqlSession.getMapper(CommodityClassifyInter.class); 
		    commMapper.DeleteBigClassify(id);
		    commMapper.DeleteSmallBigClassify(id);
		    sqlSession.commit();
		    sqlSession.close();
		}
		//查看所有商品分类
		public List<CommodityClassify> classifycla(){
			SqlSession sqlSession;
		    sqlSession = SqlSessionFactoryUtil.openSqlSession();
		    CommodityClassifyInter commMapper =  sqlSession.getMapper(CommodityClassifyInter.class); 
		    List list=commMapper.CommodityClassifyBig();
		    sqlSession.close();
			return list;
		}
		//大类修改
		public  void ChangeBigClassify(CommodityClassify cc){
			SqlSession sqlSession;
		    sqlSession = SqlSessionFactoryUtil.openSqlSession();
		    CommodityClassifyInter commMapper =  sqlSession.getMapper(CommodityClassifyInter.class); 
			commMapper.ChangeBigClassify(cc);
			sqlSession.commit();
			sqlSession.close();			
		}		
		//小类修改
		public  void ChangeSmallClassify(CommodityClassify cc){
			SqlSession sqlSession;
		    sqlSession = SqlSessionFactoryUtil.openSqlSession();
		    CommodityClassifyInter commMapper =  sqlSession.getMapper(CommodityClassifyInter.class); 
			commMapper.ChangeSmallClassify(cc);
			sqlSession.commit();
			sqlSession.close();
			
		}
		//增加小类
		public void AddSmallClassify(CommodityClassify cc){
			SqlSession sqlSession;
		    sqlSession = SqlSessionFactoryUtil.openSqlSession();
		    CommodityClassifyInter commMapper =  sqlSession.getMapper(CommodityClassifyInter.class); 
		    commMapper.AddSmallClassify(cc);
		    sqlSession.commit();
			sqlSession.close();
		}
		//展示所有小类信息
		public List<CommodityClassify> ShowSmallClassify(){
			SqlSession sqlSession;
		    sqlSession = SqlSessionFactoryUtil.openSqlSession();
		    CommodityClassifyInter commMapper =sqlSession.getMapper(CommodityClassifyInter.class);
		    List<CommodityClassify> list=commMapper.ShowSmallClassify();
		    sqlSession.close();
			return list;
		}
		
		
}


